<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
  function jump(){
	  var num = document.getElementById("num").value;
	  location.herf = "<%=basePath%>pageQuery?pageNo=" + num;
  }
</script>
<title>酷妈妈商城</title>
</head>
<body>
	<h1>产品列表</h1>
	<c:if test="${empty pageBean.products}">
		<h3>没有数据</h3>
	</c:if>
	<c:if test="${not empty pageBean.products}">
		<table border="1px" width="100%">
			<tr>
				<th>商品编号</th>
				<th>商品名称</th>
				<th>商品分类</th>
				<th>价格 ：</th>
			</tr>
			<c:forEach var="product" items="${pageBean.products}">
				<tr>
					<td>${product.id}</td>
					<td>${product.name}</td>
					<td>${product.category}</td>
					<td>${product.price}</td>
				</tr>
			</c:forEach>
			<tr>
				<td colspan="4">
				<c:if test="${pageBean.pageNo==1}">首页 上一页</c:if>
				<c:if test="${pageBean.pageNo!=1}"><a href="/pageQuery?pageNo=1">首页 </a> <a href="/pageQuery?pageNo=${pageBean.pageNo-1}">上一页</a></c:if>
				
				
				<c:set var="begin" value="1" scope="page"/>
				<c:set var="end" value="${pageBean.totalPage}" scope="page"/>
				<!-- 说明前面还有页数 -->
				<c:if test="${pageBean.pageNo - 5 >0 }">
				   <c:set var="begin" value="${pageBean.pageNo - 5}" scope="page"/>
				</c:if>
				<!-- 说明后面还有页数 -->
				<c:if test="${pageBean.pageNo + 10 <pageBean.totalPage }">
				   <c:set var="end" value="${pageBean.pageNo + 5}" scope="page"/>
				</c:if>
				
				<c:forEach begin="${begin }" end="${end }" var="i">
				   <!-- 当前页不显示链接 -->
				  <c:if test="${pageBean.pageNo == i}">
				     ${i}
				  </c:if>	
				  <c:if test="${pageBean.pageNo != i}">
				    <a href="/pageQuery?pageNo=${i }">${i}</a> 
				  </c:if>	
				   
				</c:forEach>
				
				
				<c:if test="${pageBean.pageNo==pageBean.totalPage}">下一页 尾页  </c:if>
				<c:if test="${pageBean.pageNo!=pageBean.totalPage}"><a href="/pageQuery?pageNo=${pageBean.pageNo+1 }">下一页 </a> <a href="/pageQuery?pageNo=${pageBean.totalPage }">尾页</a></c:if>
				 <input type="text" size="2" id="num" onblur="jump();"/>
				 </td>
			</tr>
		</table>
	</c:if>
</body>
</html>